package com.opcode.costa.ui.dialogs;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.opcode.costa.R;
import com.opcode.nebulamobil.base.components.ButtonBase;
import com.opcode.nebulamobil.base.components.FrameLayoutBase;
import com.opcode.nebulamobil.base.components.TextViewBase;
import com.opcode.nebulamobil.base.fragments.dialogfragments.DialogFragmentBase;
import com.opcode.nebulamobil.base.interfaces.OnButtonBaseClickListener;
import com.opcode.nebulamobil.information.ApplicationInfo;
import com.opcode.nebulamobil.information.dataforms.costadataforms.FoodDataForm;


/**
 * Bu s�n�f, se�ilen yeme�in adet bilgisinin girilmesini sa�lar. Bu fragment
 * i�erisinde bir tane de alt fragment bulunmaktad�r. Burada alt fragment
 * yap�s�n�n kurulmas�n�n nedeni farkl� tarzlarda adet bilgisinin
 * girilebilmesine imkan sa�lamakt�r. Yani radiobutton kullanarak, say�
 * girilerek veya checkbox kullan�larak bu bilgi girilebilir. Her bir giri�
 * tarz�na �zel alt fragmen tasarlanmas� planlanm��t�r. Ancak �u anki versiyonda
 * yaln�zca radiobutton kullan�lmaktad�r.
 * 
 * @author Okan ERDO�AN 9 Haz 2014
 */
public class FoodDetailDialogFragment extends DialogFragmentBase {

	private View vi;
	private FoodDataForm foodDataForm;
	private FoodDetailOptionsSubFragment foodDetailOptionSubFragment;
	private TextViewBase foodHeaderTextview;
	private ButtonBase confirmButton, declineButton;
	private FrameLayoutBase detailContainer;

	public FoodDetailDialogFragment(FoodDataForm foodDataForm) {
		this.foodDataForm = new FoodDataForm();
		this.foodDataForm.setCalorie(foodDataForm.getCalorie());
		this.foodDataForm.setFoodName(foodDataForm.getFoodName());
		this.foodDataForm.setPrice(foodDataForm.getPrice());
		this.foodDataForm.setSelectablePortions(foodDataForm.getSelectablePortions());
		this.foodDataForm.setFoodType(foodDataForm.getFoodType());
		this.foodDataForm.setKitchenID(foodDataForm.getKitchenID());
		this.foodDataForm.setFoodId(foodDataForm.getFoodId());
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		this.vi = inflater.inflate(R.layout.food_detail_dialog_fragment_layout,container, false);
		this.foodHeaderTextview = (TextViewBase) this.vi.findViewById(R.id.food_header_textview);
		this.foodHeaderTextview.setText(foodDataForm.getFoodName());

		this.foodDetailOptionSubFragment = new FoodDetailOptionsSubFragment(foodDataForm);
		subFragmentAddToChildContainer(R.id.food_speciality_detail_container,foodDetailOptionSubFragment);

		/*
		 * Bu fragment i�erisinde alt fragment al�r. Al�nan bu alt fragment
		 * i�erisinde ilgili se�im yap�l�r. Bu se�im �u anki versiyonumuzda
		 * yeme�e ait adet bilgisidir. ConfirmButon'a bas�ld��� zaman se�ili
		 * adet bilgisi foodDataForm'a eklenerek interface �zerinden
		 * dinleyicilerine bildirilir.
		 */
		this.confirmButton = (ButtonBase) this.vi
				.findViewById(R.id.confirm_button);
		this.confirmButton.setOnButtonBaseClickListener(new OnButtonBaseClickListener() {
			
			@Override
			public void onButtonBaseClick(View v) {

				ApplicationInfo.getOnFoodDetailSelectedListener()
						.onFoodDetailSelected(foodDataForm);

				dismiss();
			}
		});

		/*
		 * Adet bilgisi girmekten vazge�ilirse bu buton kullan�lmal�d�r.
		 */
		this.declineButton = (ButtonBase) this.vi
				.findViewById(R.id.decline_button);
		this.declineButton.setOnButtonBaseClickListener(new OnButtonBaseClickListener() {
			
			@Override
			public void onButtonBaseClick(View v) {
				dismiss();
			}

		});
		return this.vi;
	}

	public void onResume() {
		super.onResume();
	}
}
